package com.llsydn.ui.component.progress;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.SeekBar;
import com.llsydn.hello.R;

/**
 * @author lilinshen
 * @title 进度条component组件
 * @description 请填写相关描述
 * @date 2018/9/20 14:39
 */
public class ProgressComponentActivity extends AppCompatActivity {

    private LinearLayout ll_progress_loading;
    private ProgressBar pb_progress_loading;
    private SeekBar sb_progress_loading;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_progress);
        //初始化值
        ll_progress_loading = findViewById(R.id.ll_progress_loading);
        pb_progress_loading = findViewById(R.id.pb_progress_loading);
        sb_progress_loading = findViewById(R.id.sb_progress_loading);
        //设置监听
        sb_progress_loading.setOnSeekBarChangeListener(onSeekBarChangeListener);
    }

    /**
     * 监听对象
     */
    private SeekBar.OnSeekBarChangeListener onSeekBarChangeListener = new SeekBar.OnSeekBarChangeListener() {
        //进度改变
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            Log.e("TAG", "进度改变");
            //设置为pb_progress_loading的进度
            pb_progress_loading.setProgress(progress);
            //判断是否达到最大值
            if (progress == sb_progress_loading.getMax()) {
                //最大值，设置ll_progress_loading为不可见
                //ll_progress_loading.setVisibility(View.INVISIBLE); //不可见，但是占用空间。
                ll_progress_loading.setVisibility(View.GONE); //不可见，且不占用空间。
            } else {
                //不是最大值，设置ll_progress_loading为可见
                ll_progress_loading.setVisibility(View.VISIBLE);
            }
        }

        //按下滑杆
        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            Log.e("TAG", "按下滑杆");
        }

        //从滑杆离开
        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            Log.e("TAG", "离开滑杆");
        }
    };

}
